package parser

import (
	"regexp"
	"awesomeProject3/crawler/engine"
)

const cityListRe = `<a href="(http://www.zhenai.com/zhenghun/[0-9a-z]+)"[^>]*>([^<]*)</a>`

func ParseCityList(contents []byte) engine.ParseResult {
	result := engine.ParseResult{}
	rg := regexp.MustCompile(cityListRe)
	allSubmatch := rg.FindAllSubmatch(contents, -1)

	limit := 1
	for _, m := range allSubmatch {
		result.Items = append(result.Items, "city "+string(m[2]))
		result.Requests = append(result.Requests, engine.Request{
			Url:        string(m[1]),
			ParserFunc: ParseCity,
		})
		limit--
		if limit==0 {
			break
		}
	}
	return result
}
